Repository navigation
Batch the pre-commit final newline check - #253
Merged
Merged
Conversation
The hook used a `tail` subprocess per tracked text file, paying for thousands of process launches on every commit. Shell splitting also lost valid filenames and reported some binary files as missing an LF. Ast-grep's language-specific node regexes cannot check the raw EOF of an arbitrary tracked file reliably. Pass NUL-delimited paths and the existing exclusions to a standalone Rust checker. Read one byte for files that already end in LF; for the rest, report a violation only after ruling out NUL bytes. Keep the legacy inventories for other hooks and accept an empty selection. The generated newline-only pre-commit dispatcher and runner took 0.205s instead of 3.872s (median of seven warm runs, 2,048 synthetic tracked files on x86_64 Linux). Both versions rejected a staged missing-LF text file. Review: fixed absent paths whose parent was replaced by a file, tested production package wiring, and guarded the non-UTF-8 filename test on filesystems that forbid it. The follow-up review passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Posted by Tau
Summary
Fixes #252. The default pre-commit newline check launches
tailfor each eligible tracked file, splits some filenames incorrectly, and can mistake binary files for text. Replace those per-file processes with one standalone checker. With 2,048 synthetic tracked files and only the newline check enabled, the generated hook's median wall time fell from 3.872 s to 0.205 s (18.9×, seven warm runs on x86_64 Linux).Details
The check preserves the existing filename filters, passes Git paths as NUL-delimited records, and reads only the final byte on the passing path. If a file does not end in LF, the checker scans for NUL bytes before reporting it. NUL-free binaries without an excluded extension may still need an ignore pattern. Unlike a language-specific ast-grep rule, the checker works on the exact file bytes regardless of extension.
To exercise unusual paths, binary files, and staged versus unstaged behavior, run
nix build .#checks.x86_64-linux.gitHooks --no-link.